lobsterlayui.main(['index', 'layer', 'form', 'element', 'table'], {
    data: {
        $layui: null,
        tableins: null,
    },
    pageload: function (right) {
        console.log(right);
        this.initevent();
        this.loadpres();
    },
    initevent() {
        var self = this;
        //搜索
        layui.form.on("submit(LAY-search)", function (data) {
            self.data.tableins.reload({
                where: {
                    drugName: $("#pPresName").val(),
                },
                page: {
                    curr: 1
                }
            });
        });

        //监听行工具事件
        layui.table.on('tool(presTable)', function (obj) {
            var data = obj.data;//当前行数据
            var layEvent = obj.event;//获得lay-event的值
            if (obj.event === "detail") {
                layer.open({
                    type: 1
                    , title: '方剂详解'
                    , content: $('#dialog').html()
                    , area: ['900px', '600px']  //宽，高
                    , success: function (layero, index) {
                        layui.form.val('formDetail', data);

                    }
                });
            }
        });

    },

    //加载处方列表
    loadpres() {
        //表格绑定
        this.data.tableins = layui.table.render({
            elem: '#presTable',
            headers: lobsterlayui.GetHeaderData(),
            where: {
                drugName: $("#pPresName").val(), //获取值
            },
            height: 'full-130',
            cellMinWidth: 80,
            size: 'sm',
            toolbar: '#toolbar',
            url: lobsterlayui.GetLowCodeUrl('tscnmedpres.getcnMedPres'),
            page: true,
            even: true,
            cols: [[
                {
                    width: "120", field: '方剂名称', fixed: 'left', title: '方剂名称', templet: function (res) {
                        return res.方剂名称;
                    }
                },
                { width: "300", field: '方剂组成', title: '方剂组成' },
                { width: "120", field: '分类', title: '分类' },
                { width: "150", field: '功用', title: '功用' },
                { width: "200", field: '主治', title: '主治' },
                { width: "150", field: '炮制', title: '炮制' },
                { width: "150", field: '用法用量', title: '用法用量' },
                { width: "90", field: '功用', title: '功用', align: 'center', templet: '#flagTpl' },
                { width: "150", field: '方解', title: '方解', hide: true },
                { width: "150", field: '禁忌', title: '禁忌', hide: true },
                { width: "150", field: '化裁', title: '化裁', hide: true },
                { width: "150", field: '附方', title: '附方', hide: true },
                { width: "150", field: '附注', title: '附注', hide: true },
                { width: "150", field: '文献', title: '文献', hide: true },
                { width: "150", field: '运用', title: '运用', hide: true },
                { width: "120", title: '操作', fixed: 'right', align: 'center', toolbar: '#option' }   //操作script的id                  
            ]],
            parseData: function (res) {
                return {
                    code: res.code,
                    msg: res.msg,
                    count: res.data.count,
                    data: res.data.list
                }
            }
        });
    }

})